﻿using System;
using System.Threading;

using DreamCube.WebServer.WinServiceModel;
using DreamCube.Foundation.Basic.Utility;

namespace DreamCube.WebServer.WinService
{
    /// <summary>
    /// 这个是守护windows service的守护进程
    /// </summary>
    internal class KeepWinServiceLiveServer : KeepLiveServer
    {
        /// <summary>
        /// 检查服务器
        /// </summary>
        public override void DoCheckServer()
        {
            try
            {
                if (MyWinService.GetServiceStatusEx(Common.ServiceName) != MyWinService.ServiceStatus.Running)
                    MyWinService.StartService(Common.ServiceName, new TimeSpan(0, 0, 30));
            }
            catch (Exception ex)
            {
                MyLog.MakeLog(ex);
            }
            finally
            {
                timer.Change(5000, Timeout.Infinite);
            }
        }
    }
}
